home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / lcsrc.arc / CRT_LN32.C < prev    next >
Text File  |  1985-04-05  |  4KB  |  149 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. /******************************************************************
  7.  *
  8.  * name        crt_line320 - plot lines w/ fast 320x200 point routine
  9.  *
  10.  * synopsis    crt_line320(row1, col2, row2, col2, color)
  11.  *        int row1,col2,row2,col2,color;
  12.  *
  13.  * description    This routine uses a simple octantal DDA to plot 
  14.  *        lines on your 320 x 200 COLOR graphics screen.  The
  15.  *        screen needs to be set to graphics mode, of course...
  16.  *
  17.  * notes    This routine is still written in 'C'.  It is faster 
  18.  *        than many of the other line draw routines I have seen
  19.  *        around, but still relatively slow compared to assembler.
  20.  *        Next released version of the libraries will have this 
  21.  *        one written in assembler...
  22.  *
  23.  *        Works only in 320x200 color graphics mode!!
  24.  * 
  25.  * bugs        Better be sure that your x and y values are in range
  26.  *        no range checking is done.
  27.  ********************************************************************/
  28.  
  29. crt_line320(startx, starty, endx, endy, color)
  30. int  startx, starty, endx, endy, color;
  31.     {
  32.     int count, deltax, deltay, error, t;
  33.  
  34.  
  35.     if (endx < startx)
  36.         {
  37.         t = startx;             /* fold quadrants 2, 3 to 1, 4  */
  38.         startx = endx;
  39.         endx = t;
  40.         t = starty;
  41.         starty = endy;
  42.         endy = t;
  43.         }
  44.     deltax = endx - startx;
  45.     deltay = endy - starty;
  46.     if (deltay < 0)
  47.         {
  48.         if (-deltay > deltax)   /* octant 7             */
  49.             {
  50.             count = -deltay;
  51.             error = deltay / 2;
  52.             do
  53.                 {
  54. /*              if (flag)
  55.                     pixerase(startx + XOFF, YOFF - starty);
  56.                 else
  57.                     pixplot(startx + XOFF, YOFF - starty);
  58.  
  59. */
  60.         crt_ps32(startx, starty, color);
  61.  
  62.                 starty--;è                if ((error += deltax) >= 0)
  63.                     {
  64.                     startx++;
  65.                     error += deltay;
  66.                     }
  67.                 }
  68.             while (--count >= 0);
  69.             }
  70.         else                    /* octant 8             */
  71.             {
  72.             count = deltax;
  73.             error = -deltax / 2;
  74.             do
  75.                 {
  76. /*
  77.                 if (flag)
  78.                     pixerase(startx + XOFF, YOFF - starty);
  79.                 else
  80.                     pixplot(startx + XOFF, YOFF - starty);
  81.  
  82. */
  83.  
  84.         crt_ps32(startx, starty, color);
  85.  
  86.  
  87.                 startx++;
  88.                 if ((error -= deltay) >= 0)
  89.                     {
  90.                     starty--;
  91.                     error -= deltax;
  92.                     }
  93.                 }
  94.             while (--count >= 0);
  95.             }
  96.         }
  97.     else if (deltay > deltax)       /* octant 2         */
  98.         {
  99.         count = deltay;
  100.         error = -deltay / 2;
  101.         do
  102.             {
  103. /*
  104.             if (flag)
  105.                 pixerase(startx + XOFF, YOFF - starty);
  106.             else
  107.                 pixplot(startx + XOFF, YOFF - starty);
  108.  
  109. */
  110.         crt_ps32(startx , starty, color);
  111.  
  112.  
  113.             starty++;
  114.             if ((error += deltax) >= 0)
  115.                 {
  116.                 startx++;
  117.                 error -= deltay;
  118.                 }
  119.             }
  120.         while (--count >= 0);
  121.         }è    else                        /* octant 1             */
  122.         {
  123.         count = deltax;
  124.         error = -deltax/2;
  125.         do
  126.             {
  127.   
  128. /*
  129.           if (flag)
  130.                 pixerase(startx + XOFF, YOFF - starty);
  131.             else
  132.                 pixplot(startx + XOFF, YOFF - starty);
  133. */
  134.         crt_ps32(startx , starty, color);
  135.  
  136.  
  137.             startx++;
  138.             if ((error += deltay) >= 0)
  139.                 {
  140.                 starty++;
  141.                 error -= deltax;
  142.                 }
  143.             }
  144.         while (--count >= 0);
  145.         }
  146.     }
  147.  
  148.  
  149.